<?php
/*!
* TalkBack basic-client post page
* This file shows how to use the TalkBack library to post a talkback notification. 
* @Author: Elie Bursztein (elie _AT_ cs.stanford.edu)
* @Version: 1.0
* @Url: http://talkback.stanford.edu
* @Licence: LGPL
*/
?>

<?

	$url = "http://127.0.0.1:8888/basic_client/index.php";
	$title = "hey joe !";
	$excerpt = "I love this song!";
	
	require_once "config.php"; 				//configuration file
	require_once "../library/talkback.php";	//the talkback cslient library 

	//creating an instance of the lib
	$tb = new TalkBack($dataDir, $debug);
	
	//loading public key and private key *hence the TRUE*
	$tb->load(TRUE);
	

	//fetch our destination blog notification page
	if(!$tb->fetchBlogInfo($url))
		die("The requested blog do not support the talkback protocol\n");
		
	//fetch our destination blog crypto suite and public key
	if(!$tb->fetchBlogCrypto($url))
		die("The requested blog do not provide its public key, please notify it\n");
	
		
	//requesting the seed from the authority
	// getting the seed should be done only one time by post.here we only post one notificatio so we don't implement the checking logic.
	if ($tb->getSeed($url) == 0)
		die("the authority refused to grant us a seed. Rate limiting must be exceeded. View you account status to request more
		notification\n"); 
	
	//get the notification token	
	if ((($token = $tb->getToken()) == -1))
		die("Seed not availabe did you call getSeed() ?\n");
	elseif ($token == -2)
		die("Seed exhausted, please request another token\n");
		
	//generate the notification	
	if (!$tb->createNotification($blogName, $blogUrl, $title, $excerpt, $token)) 
		die("can't build the notification something must be wrong, use the debug mode to know more\n");
	
	//sending the notfication
	if (!$tb->sendNotification()) 
		die("can't send notification something must be wrong, maybe the receiver is offline or the notification page is broken\n");
	
	
?>